﻿<%@ Page Language="C#" AutoEventWireup="false" CodeFile="recSubSectorform.aspx.cs"
    Inherits="SIPO.Web.Forms.Administration.Catalog.recSubSectorform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Sub Sector Form</title>

    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script type="text/javascript">

        $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
        $("#btnClose").button({ icons: { primary: "ui-icon-close"} });

        $('#btnClose').click(function () {
            parent.$('#dialog').dialog("close");
        });
 
    </script>
    <script type="text/javascript">

        $(document).ready(function () {

            // 1. prepare the validation rules and messages.
            var rules = {
                ddlSector: "required",
                txtCode: {
                    required: true,
                    maxlength: 10
                },
                txtName: "required",
                ddlBank: "required",
            };
            var messages = {
                ddlSector: "Sektor harus diisi",
                txtCode: {
                    required: "Kode Sub Sektor harus diisi",
                    maxlength: "Panjang maksimal Kode Sub Sektor adalah 10"
                },
                txtName: "Nama Sub Sektor harus diisi",
                ddlBank: "Bank harus diisi",
            };

            // tidak boleh karakter khusus
            $("#txtCode").inputmask("Regex", { regex: "[A-Za-z0-9]*" });
            
            // 2. Initiate the validator
            var validator = new jQueryValidatorWrapper("form1", rules, messages);

            // 3. Set the click event to do the validation
            $("#btnSave").click(function () {

                if (!validator.validate())
                    return;

                var code = $('#txtCode').val();
                var name = $('#txtName').val();
                var sectorid = $("#ddlSector option:selected").val();
                var bankid = $("#ddlBank option:selected").val();

                var id = $('#<%= hfID.ClientID %>').val();

                var objrecSubSector = new Object();

                objrecSubSector.SubSectorID = id;
                objrecSubSector.SubSectorCode = encodeURIComponent(code);
                objrecSubSector.SubSectorName = encodeURIComponent(name);
                objrecSubSector.SectorID = encodeURIComponent(sectorid);
                objrecSubSector.BankID = encodeURIComponent(bankid);

                jsonData = JSON.stringify(objrecSubSector);
                var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/administration/catalog/recSubSectorhandler.ashx") %>';

                if (id == 0)
                    CallAjax(handlerUrl, "?method=insert", jsonData);
                else {
                    CallAjax(handlerUrl, "?method=update", jsonData);
                }

                parent.$('#dialog').dialog('close');

                setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

                return false;
            });


        });
    
    </script>
    <script type="text/javascript">

        function ClearText() {
            $('#txtCode').val('');
            $('#txtName').val('');
        }        
         
    </script>
</head>
<body onload="ClearText();">
    <form id="form1" runat="server">
    <table border="0">
        <tr>
            <td style="width: 50">
                Sektor
            </td>
            <td>
                :
            </td>
            <td>
                <asp:DropDownList ID="ddlSector" runat="server" Width="300">
                </asp:DropDownList>
                &nbsp;<span style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Kode Sub Sektor
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtCode" MaxLength="10" runat="server" Width="200"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td style="width: 50">
                Nama Sub Sektor
            </td>
            <td>
                :
            </td>
            <td>
                <asp:TextBox ID="txtName" runat="server" Width="300" MaxLength="100"></asp:TextBox>&nbsp;<span
                    style="color: Red;">*</span>
            </td>
        </tr>
         <tr>
            <td style="width: 50">
                Bank
            </td>
            <td>
                :
            </td>
            <td>
                <asp:DropDownList ID="ddlBank" runat="server" Width="300">
                </asp:DropDownList>
                &nbsp;<span style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">
                        Save</button>
                    <button id="btnClose" type="button">
                        Close</button>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td>
                <asp:HiddenField ID="hfID" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
